package com.aiju.cash.util.InputFilter;

import android.text.InputFilter;
import android.text.Spanned;

import com.aiju.utils.T;

/**
 * @author: 佐为
 * @date: 2017-05-11 15:04
 * @version: V1.0
 * @Description: 小于20万两位小数
 */
public class AijuInputFilter implements InputFilter {
    @Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
        String oriValue = dest.toString();
        StringBuffer sb = new StringBuffer(oriValue);
        sb.append(source);

        String newValue = sb.toString();
        Double aDouble = Double.valueOf(newValue);
        if (aDouble > 200000) {
            T.ToastShort("输入金额不能超过20万");
            return "";
        }
        if (dest.toString().contains(".")) {
            int index = dest.toString().indexOf(".");
            int mlength = dest.toString().substring(index).length();
            if (mlength == 3) {
                return "";
            }
        }
        return source;
    }
}
